﻿<UserControl x:Class="MathematicallySafe.HeadCounter.Views.RaiderHistoryView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ViewModels="clr-namespace:MathematicallySafe.HeadCounter.ViewModels"
    xmlns:Views="clr-namespace:MathematicallySafe.HeadCounter.Views">

    <UserControl.Resources>

        <Views:HistoryAttendanceBackgroundConverter x:Key="HistoryAttendanceBackgroundConverter" IsBackground="True"/>
        <Views:HistoryAttendanceBackgroundConverter x:Key="HistoryAttendanceForegroundConverter" IsBackground="False"/>

        <DataTemplate x:Key="LootItemTemplate" DataType="LootItem">
            <TextBlock>
                <Hyperlink TextDecorations="None" NavigateUri="{Binding LootUri}" RequestNavigate="HyperlinkOnRequestNavigate">
                    <TextBlock Style="{StaticResource LootHyperlinkStyle}" Text="{Binding Path=Name}">
                        <TextBlock.ToolTip>
                            <ToolTip Content="{Binding}" Style="{StaticResource ItemTooltipTemplate}" />
                        </TextBlock.ToolTip>
                    </TextBlock>
                </Hyperlink>
            </TextBlock>
        </DataTemplate>

        <DataTemplate x:Key="RaidHistoryLineTemplate" DataType="ViewModels:RaiderRaidHistoryLine">
            <Grid Margin="0,1,0,2" TextElement.FontFamily="Calibri" TextElement.FontSize="12">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="2*" />
                    <ColumnDefinition Width="4*" />
                </Grid.ColumnDefinitions>
            
                <TextBlock Grid.Column="0" Padding="2" 
                           Text="{Binding Date, StringFormat=\{0:dd MMM yy\}}" 
                           Background="{Binding Converter={StaticResource HistoryAttendanceBackgroundConverter}}"
                           Foreground="{Binding Converter={StaticResource HistoryAttendanceForegroundConverter}}"/>
                
                <TextBlock Grid.Column="1" Padding="2" 
                           Text="{Binding Location}" 
                           Background="{Binding Converter={StaticResource HistoryAttendanceBackgroundConverter}}"
                           Foreground="{Binding Converter={StaticResource HistoryAttendanceForegroundConverter}}"/>
                
                <ItemsControl Grid.Column="2" Style="{StaticResource WrappingItemsPanel}" VerticalAlignment="Top"
                              ItemsSource="{Binding LootWon}" ItemTemplate="{StaticResource LootItemTemplate}" 
                              ScrollViewer.HorizontalScrollBarVisibility="Disabled"/>
            </Grid>
        </DataTemplate>

    </UserControl.Resources>

    <Grid Grid.Row="0" Grid.Column="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto">
            <ItemsControl ItemsSource="{Binding RaidingHistory}" ItemTemplate="{StaticResource RaidHistoryLineTemplate}"/>
        </ScrollViewer>

        <Grid Grid.Row="1" Margin="8,16,8,4" TextElement.FontFamily="Calibri">
            
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            
            <TextBlock Grid.Row="0" Grid.Column="0" Text="Attended" TextAlignment="Center" VerticalAlignment="Center" Margin="8,0"
                       Background="{StaticResource AttendedBackground}" Foreground="{StaticResource AttendedForeground}" />    
            
            <TextBlock Grid.Row="0" Grid.Column="1" Text="Attended Optional" TextAlignment="Center" VerticalAlignment="Center" Margin="8,0"
                       Background="{StaticResource AttendedOptionalBackground}" Foreground="{StaticResource AttendedOptionalForeground}" />    
            
            <TextBlock Grid.Row="0" Grid.Column="2" Text="Missed" TextAlignment="Center" VerticalAlignment="Center" Margin="8,0"
                       Background="{StaticResource MissedBackground}" Foreground="{StaticResource MissedForeground}" />    
            
            <TextBlock Grid.Row="0" Grid.Column="3" Text="Missed Optional" TextAlignment="Center" VerticalAlignment="Center" Margin="8,0"
                       Background="{StaticResource MissedOptionalBackground}" Foreground="{StaticResource MissedOptionalForeground}" />    
            
        </Grid>
    </Grid>
</UserControl>
